package com.wind.taobao.api.trade.item.convert
{
	import com.wind.taobao.api.trade.item.model.Video;
	import com.wind.taobao.core.util.TaobaoConstants;
	
	import mx.collections.ArrayCollection;


	/**
	 * Video转换器
	 * @author fxy
	 *
	 */
	public class VideoConvert
	{
		/**
		 * 转换Video集合
		 */
		public static function convertVideos(value:Object, type:String="json"):ArrayCollection
		{
			var videos:ArrayCollection=new ArrayCollection();
			if (value != null)
			{
				if (type == TaobaoConstants.JSON)
				{
					if ((value as Array).length > 0)
					{
						for (var i:uint=0; i < (value as Array).length; i++)
						{
							videos.addItem(convertVideo((value as Array)[i]));
						}
					}
				}
				else
				{
					//TODO
				}
			}
			return videos;
		}

		/**
		 * 转换Video
		 */
		public static function convertVideo(value:Object, type:String="json"):Video
		{
			var video:Video=new Video();
			if (value == null)
				return video;
			if (type == TaobaoConstants.XML)
			{
				video=convertXMLToVideo(XML(value), video);
			}
			else
			{
				video=convertJSONToVideo(value, video);
			}
			return video;
		}

		/**
		 * JSON转换为Video
		 */
		private static function convertJSONToVideo(json:Object, video:Video):Video
		{
			if (json.hasOwnProperty(TaobaoConstants.ID))
			{
				video.id=json[TaobaoConstants.ID];
			}
			if (json.hasOwnProperty(TaobaoConstants.VIDEO_ID))
			{
				video.video_id=json[TaobaoConstants.VIDEO_ID];
			}
			if (json.hasOwnProperty(TaobaoConstants.URL))
			{
				video.url=json[TaobaoConstants.URL];
			}
			if (json.hasOwnProperty(TaobaoConstants.CREATED))
			{
				video.created=json[TaobaoConstants.CREATED];
			}
			if (json.hasOwnProperty(TaobaoConstants.MODIFIED))
			{
				video.modified=json[TaobaoConstants.MODIFIED];
			}
			return video;
		}

		/**
		 * XML转换为Video
		 */
		private static function convertXMLToVideo(value:XML, video:Video):Video
		{
			return video;
		}


	}
}